package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-06-02 21:47
 */
public class LeetCode2559_VowelString {
    public int[] vowelStrings(String[] words, int[][] queries) {
        int[] prefixSum = new int[words.length + 1];
        for (int i = 0; i < words.length; i++) {
            int val = isVowelWord(words[i]) ? 1 : 0;
            prefixSum[i + 1] = prefixSum[i] + val;
        }
        int[] res = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int start = queries[i][0], end = queries[i][1];
            res[i] = prefixSum[end + 1] - prefixSum[start];
        }
        return res;
    }
    
    private boolean isVowelWord(String word) {
        return isVowelChar(word.charAt(0)) && isVowelChar(word.charAt(word.length() - 1));
    }
    
    private boolean isVowelChar(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
}
